# Data and Code For `Imperial Legal Politics` paper

This is the code and data to replicate the analysis in Lazarev and Skougarevskiy's Imperial Legal Politics paper.

## Installation

To replicate the analysis you need to install the required versions of R dependencies listed in `DEPENDENCIES`. `code/helper_functions/install_dependencies.r` automates this step, but you may still need to install the system libraries manually with [Homebrew](https://brew.sh) or `apt-get`, depending on your platform. Finally, you need to declare the environment variable `IMPERIAL_LEGAL_POLITICS_REPLICATION_PATH` in your shell pointing to the repository. Or, better yet, you can add it in your `.Renviron` with
```console
user:~$ echo 'IMPERIAL_LEGAL_POLITICS_REPLICATION_PATH="path_to_folder"' >> ~/.Renviron
```
or with 
```R
usethis::edit_r_environ()
```

## Repository structure

```
/
├── README.md                                                   # This file
├── AUTHORS                                                     # List of contributors
├── DEPENDENCIES                                                # List of R packages with dependencies
├── code/
|    ├── 1_plot_composition_of_cases_crimea.r                   # Produces Fig 1, S2
|    ├── 2_compare_win_rates_crimea_krasnodar.r                 # Produces Tab 1, S4; Fig 2, 3, S3
|    ├── 3a_judgelevel_analysis_crimea.r                        # Produces Tab 2A, 2B, S8, S9
|    ├── 3b_judgelevel_analysis_krasnodar.r                     # Produces Tab 2A, 2B
|    ├── 4a_within_win_regressions.r                            # Produces Tab 3; Fig S4
|    ├── 4b_within_win_regressions_crimea_krasnodar_combined.r  # Produces Tab S10
|    ├── 4c_within_win_regressions_matched.r                    # Produces Tab S11
|    ├── 5_compute_summary_stat_krasnodar.r                     # Produces Tab S2, S3
|    ├── 6_compute_selection_into_litigation_crimea_krasnodar.r # Produces Tab S5, S6
|    ├── 7_test_for_random_case_assignment.r                    # Produces Tab S7
|    └── helper_functions/
|        └── install_dependencies.r                             # Installs dependencies
├── data/                                          
|    ├── crimea_case_outcomes_side_instance.rdata               # Case-side-instance-level data on commercial court cases in Crimea
|    ├── krasnodar_case_outcomes_side_instance.rdata            # Case-side-instance-level data on commercial court cases in Krasnodar
|    ├── crimea_krasnodar_orgs_panel.rdata                      # Yearly panel with the universe of legal entities in Crimea/Krasnodar
|    ├── all_russia_government_yearly_win_rate.csv              # All-Russia government yearly win rates derived from Volkov et al. (2023) data
|    └── all_russia_local_entity_yearly_win_rate.csv            # All-Russia Local entity yearly win rates derived from Volkov et al. (2023) data
├── tables/                                             
|    ├── table1_government_win_rates_byagency.csv               # Table 1, top panel
|    ├── table1_local_entity_win_rates_byagency.csv             # Table 1, bottom panel
|    ├── table2_government_judges_table_crimea.csv              # Table 2, Panel A, Crimea
|    ├── table2_government_judges_table_krasnodar.csv           # Table 2, Panel A, Krasnodar
|    ├── table2_local_entity_judges_table_crimea.csv            # Table 2, Panel B, Crimea
|    ├── table2_local_entity_judges_table_krasnodar.csv         # Table 2, Panel B, Krasnodar
|    ├── table3_twfe_all.tex                                    # Table 3
|    ├── tableS2_government_year_table_krasnodar.csv            # Table S2
|    ├── tableS3_private_year_table_krasnodar.csv               # Table S3
|    ├── tableS4_government_win_rates_byagency_excl_pension.csv # Table S4, Panel A
|    ├── tableS4_government_win_rates_byagency_only_civil.csv   # Table S4, Panel B
|    ├── tableS5_use_courts_table.csv                           # Table S5
|    ├── tableS6_case_counts_government_local.tex               # Table S6
|    ├── tableS7_crimea_random_government.csv                   # Table S7, Panel A, Crimea
|    ├── tableS7_crimea_random_government.csv                   # Table S7, Panel A, Krasnodar
|    ├── tableS7_crimea_random_local_entity.csv                 # Table S7, Panel B, Crimea
|    ├── tableS7_krasnodar_random_local_entity.csv              # Table S7, Panel B, Krasnodar
|    ├── tableS8_judgeassignment_government.tex                 # Table S8
|    ├── tableS9_judgeassignment_local_entity.tex               # Table S9
|    ├── tableS10_twfe_all_krasnodar_crimea.tex                 # Table S10
|    └── tableS11_twfe_all_matched.tex # Table A.2
└── figures/                                             
     ├── figure1_government_year_freqs_plot.pdf                 # Figure 1
     ├── figure2_government_win_rates_overall_plot.pdf          # Figure 2
     ├── figure3_local_entity_win_rates_overall_plot.pdf        # Figure 3
     ├── figureS2_cases_by_federal_agency_plot.pdf              # Figure S2
     ├── figureS3_government_win_rates_overall_excl_pension_plot.pdf   # Figure S3, Panel A
     ├── figureS3_government_win_rates_overall_only_civil_plot.pdf   # Figure S3, Panel B
     └── figureS4_advantage_byyear_plot.pdf                     # Figure S4
```


## Data description

The primary files to consider are `data/{crimea,krasnodar}_case_outcomes_side_instance.rdata`. They adopt the following structure (the entire data for [one case](https://kad.arbitr.ru/card/00016224-9703-4a1c-9d7d-5b24a1278cd6); NB: the link to the case in the official case docket may be inaccessible outside Russia):

```
                                 caseid                           documentid    instanceLevel                   caseStage   caseTypeCode
1: 00016224-9703-4a1c-9d7d-5b24a1278cd6 7b7e4073-6f28-481f-bd2c-21931c6749fd 1_first_instance Рассмотрение дела завершено administrative
2: 00016224-9703-4a1c-9d7d-5b24a1278cd6 a8f28ed8-7f2c-4beb-8c28-4b7a7a4e8620         2_appeal Рассмотрение дела завершено administrative
3: 00016224-9703-4a1c-9d7d-5b24a1278cd6 7b7e4073-6f28-481f-bd2c-21931c6749fd 1_first_instance Рассмотрение дела завершено administrative
4: 00016224-9703-4a1c-9d7d-5b24a1278cd6 a8f28ed8-7f2c-4beb-8c28-4b7a7a4e8620         2_appeal Рассмотрение дела завершено administrative
5: 00016224-9703-4a1c-9d7d-5b24a1278cd6 7b7e4073-6f28-481f-bd2c-21931c6749fd 1_first_instance Рассмотрение дела завершено administrative
6: 00016224-9703-4a1c-9d7d-5b24a1278cd6 a8f28ed8-7f2c-4beb-8c28-4b7a7a4e8620         2_appeal Рассмотрение дела завершено administrative
                                                                                  caseCategoryUnified caseState registrationDate isSimpleJustice judicialOrder sideNumber    category
1: 32.1.2. об оспаривании решений таможенных органов о привлечении к административной ответственности  finished       2017-04-19               0             0          1       Истец
2: 32.1.2. об оспаривании решений таможенных органов о привлечении к административной ответственности  finished       2017-04-19               0             0          1       Истец
3: 32.1.2. об оспаривании решений таможенных органов о привлечении к административной ответственности  finished       2017-04-19               0             0          2    Ответчик
4: 32.1.2. об оспаривании решений таможенных органов о привлечении к административной ответственности  finished       2017-04-19               0             0          2    Ответчик
5: 32.1.2. об оспаривании решений таможенных органов о привлечении к административной ответственности  finished       2017-04-19               0             0          3 Третье лицо
6: 32.1.2. об оспаривании решений таможенных органов о привлечении к административной ответственности  finished       2017-04-19               0             0          3 Третье лицо
          inn          ogrn                                                      name             legalname            type federal_agency_type    okved okved_section
1: 2361000676 1082361000765 ОБЩЕСТВО С ОГРАНИЧЕННОЙ ОТВЕТСТВЕННОСТЬЮ 'КУБАНЬТРЕЙДМЕТ'  ООО 'КУБАНЬТРЕЙДМЕТ' private_company                <NA>    46.77             G
2: 2361000676 1082361000765 ОБЩЕСТВО С ОГРАНИЧЕННОЙ ОТВЕТСТВЕННОСТЬЮ 'КУБАНЬТРЕЙДМЕТ'  ООО 'КУБАНЬТРЕЙДМЕТ' private_company                <NA>    46.77             G
3: 2309031505 1022301441238                                     КРАСНОДАРСКАЯ ТАМОЖНЯ КРАСНОДАРСКАЯ ТАМОЖНЯ  federal_agency                 fts 84.11.40             O
4: 2309031505 1022301441238                                     КРАСНОДАРСКАЯ ТАМОЖНЯ КРАСНОДАРСКАЯ ТАМОЖНЯ  federal_agency                 fts 84.11.40             O
5: 2361000676 1082361000765 ОБЩЕСТВО С ОГРАНИЧЕННОЙ ОТВЕТСТВЕННОСТЬЮ 'КУБАНЬТРЕЙДМЕТ'  ООО 'КУБАНЬТРЕЙДМЕТ' private_company                <NA>    46.77             G
6: 2361000676 1082361000765 ОБЩЕСТВО С ОГРАНИЧЕННОЙ ОТВЕТСТВЕННОСТЬЮ 'КУБАНЬТРЕЙДМЕТ'  ООО 'КУБАНЬТРЕЙДМЕТ' private_company                <NA>    46.77             G
                                                 okved_section_name_eng       okved_chapter_name                                           okopf age total_assets net_assets staffsize
1: Wholesale and retail trade; repair of motor vehicles and motorcycles       торг опт кроме а/с        общества с ограниченной ответственностью   7       592909     -10869         6
2: Wholesale and retail trade; repair of motor vehicles and motorcycles       торг опт кроме а/с        общества с ограниченной ответственностью   7       592909     -10869         6
3:        Public administration and defence; compulsory social security гос упр воен и соц обесп федеральные государственные казенные учреждения   7           NA         NA        NA
4:        Public administration and defence; compulsory social security гос упр воен и соц обесп федеральные государственные казенные учреждения   7           NA         NA        NA
5: Wholesale and retail trade; repair of motor vehicles and motorcycles       торг опт кроме а/с        общества с ограниченной ответственностью   7       592909     -10869         6
6: Wholesale and retail trade; repair of motor vehicles and motorcycles       торг опт кроме а/с        общества с ограниченной ответственностью   7       592909     -10869         6
                             instanceId instanceNumber                date              courtName  courtTag  presiding_judge                    presiding_judgeId
1: a24147e9-b107-4691-994f-f35b635cc4fa              1 2019-03-20 12:28:04 АС Краснодарского края KRASNODAR   Чесноков А. А. abf2f05c-ec64-42ef-9771-bb96e8dc7b36
2: 26c37d8d-de6b-46b3-93f5-4486b54bbb0e              2 2019-06-03 00:00:00                 15 ААС     15AAS Филимонова С. С. 1a1a9657-3f3e-4e90-8d19-566f56d52d3f
3: a24147e9-b107-4691-994f-f35b635cc4fa              1 2019-03-20 12:28:04 АС Краснодарского края KRASNODAR   Чесноков А. А. abf2f05c-ec64-42ef-9771-bb96e8dc7b36
4: 26c37d8d-de6b-46b3-93f5-4486b54bbb0e              2 2019-06-03 00:00:00                 15 ААС     15AAS Филимонова С. С. 1a1a9657-3f3e-4e90-8d19-566f56d52d3f
5: a24147e9-b107-4691-994f-f35b635cc4fa              1 2019-03-20 12:28:04 АС Краснодарского края KRASNODAR   Чесноков А. А. abf2f05c-ec64-42ef-9771-bb96e8dc7b36
6: 26c37d8d-de6b-46b3-93f5-4486b54bbb0e              2 2019-06-03 00:00:00                 15 ААС     15AAS Филимонова С. С. 1a1a9657-3f3e-4e90-8d19-566f56d52d3f
                              judgeId_1          judge_1                            judgeId_2        judge_2                            judgeId_3         judge_3 judgeId_4 judge_4
1: abf2f05c-ec64-42ef-9771-bb96e8dc7b36   Чесноков А. А.                                 <NA>           <NA>                                 <NA>            <NA>      <NA>    <NA>
2: 1a1a9657-3f3e-4e90-8d19-566f56d52d3f Филимонова С. С. c6051975-3a04-45cc-b2d3-ecfb1cbae1b4 Гуденица Т. Г. b242efcb-54cb-4f9b-93e6-288e848f70cc Соловьева М. В.      <NA>    <NA>
3: abf2f05c-ec64-42ef-9771-bb96e8dc7b36   Чесноков А. А.                                 <NA>           <NA>                                 <NA>            <NA>      <NA>    <NA>
4: 1a1a9657-3f3e-4e90-8d19-566f56d52d3f Филимонова С. С. c6051975-3a04-45cc-b2d3-ecfb1cbae1b4 Гуденица Т. Г. b242efcb-54cb-4f9b-93e6-288e848f70cc Соловьева М. В.      <NA>    <NA>
5: abf2f05c-ec64-42ef-9771-bb96e8dc7b36   Чесноков А. А.                                 <NA>           <NA>                                 <NA>            <NA>      <NA>    <NA>
6: 1a1a9657-3f3e-4e90-8d19-566f56d52d3f Филимонова С. С. c6051975-3a04-45cc-b2d3-ecfb1cbae1b4 Гуденица Т. Г. b242efcb-54cb-4f9b-93e6-288e848f70cc Соловьева М. В.      <NA>    <NA>
   judgeId_5 judge_5         publishDate claimSum recoverySum   resultCode countDocumentsByParties countDocumentsByCourt claimSum_deflated recoverySum_deflated parties_present
1:      <NA>    <NA> 2019-03-21 12:28:04        0           0 notSatisfied                       9                    10                 0                    0               1
2:      <NA>    <NA> 2019-06-04 20:16:02        0           0   notChanged                       5                     3                 0                    0               1
3:      <NA>    <NA> 2019-03-21 12:28:04        0           0 notSatisfied                       9                    10                 0                    0               1
4:      <NA>    <NA> 2019-06-04 20:16:02        0           0   notChanged                       5                     3                 0                    0               1
5:      <NA>    <NA> 2019-03-21 12:28:04        0           0 notSatisfied                       9                    10                 0                    0               0
6:      <NA>    <NA> 2019-06-04 20:16:02        0           0   notChanged                       5                     3                 0                    0               0
   representative
1:   СОЛОВЬЕВ А В
2:   СОЛОВЬЕВ А В
3:     ПЕРШИН И В
4:     ПЕРШИН И В
5:           <NA>
6:           <NA>

```

Each line in this file represents a party's (`sideNumber`) participation in a case (`caseid`) in a court of a given instance (`instanceNumber`). The case in the above example with `caseid == 00016224-9703-4a1c-9d7d-5b24a1278cd6` is repeated six times because there are 3 sides (their role is coded in `category` variable: Plaintiff, Respondent and Third Party; NB: we exclude third parties from the analysis) and two instances where this case was heard (variable `instanceLevel`: first instance and appellate court). The variable `resultCode` keeps the side-invariant case outcome: whether the claim was satisfied/satisfied partially/not satisfied or dismissed in the court of first instance or this ruling was reversed or sustained the the appellate court or court of cassation.

These two files `{crimea,krasnodar}_case_outcomes_side_instance.rdata` form the backbone of the data since any information on sides or parties can be derived from the case-side-instance-level varying data.

Additionally, we include `data/crimea_krasnodar_orgs_panel.rdata` with the yearly panel of the universe of legal entities in Crimea/Krasnodar and the counts of their cases in commercial courts, as well as their financial statements data. This data is used to study the selection into litigation in the two regions.

Finally, we include two data files with all-Russia statistics on win rates: `data/all_russia_government_yearly_win_rate.csv` and `all_russia_local_entity_yearly_win_rate.csv`. They are derived from the data first introduced in [Volkov et al. (2023)](https://doi.org/10.1016/j.ssresearch.2023.102875).

Note that we omit the data and code for our algorithm to infer Russian entity types described in Appendix 2. This is due to (a) storage constraints (the algorithm operates with entity-year panels with almost 200 million observations), (b) data restrictions (the algorithm relies on the all-Russia panel of legal entities that we purchased from the Federal Tax Service).

### Selected variables in `{crimea,krasnodar}_case_outcomes_side_instance.rdata`

Below is a list of selected variables in our case-side-instance-level varying data with descriptions. We omit descriptions for derived variables.

```
 1:                  caseid # ID of case (see http://kad.arbitr.ru/card/[caseid]) (case-varying)
 2:              documentid # ID of document with ruling (see https://kad.arbitr.ru/Document/Pdf/[documentid]) (case-instance-varying)
 3:           instanceLevel # Numeric ID of case instance (instance-varying)
 4:               caseStage # Stage of case proceedings (case-varying)
 5:            caseTypeCode # Type of case (case-varying)
 6:     caseCategoryUnified # Cleaned up case category (case-varying)
 7:               caseState # Is case finished (case-varying)
 8:        registrationDate # Case filing date (case-varying)
 9:         isSimpleJustice # Is in simplified mode (art. 226 of APK) (case-varying)
10:           judicialOrder # Has any mention of judicial order (art. 229 of APK) in case documents (case-varying)
11:              sideNumber # Numeric id of party to the case (side-varying)
12:                category # Party role: plaintiff, respondent, etc. (side-varying)
13:                     inn # Taxpayer identifier of a party (side-varying)
14:                    ogrn # OGRN identifier of a party (side-varying)
15:                    name # Name of a party from court data (side-varying)
16:               legalname # Name of a party from the business register (after matching on INN/OGRN with EGRUL/EGRIP) (side-varying)
17:                    type # Party type: from the Institute for the Rule of Law coding of entity types (side-varying)
18:     federal_agency_type # Type of federal agency as party: from the Institute for the Rule of Law coding of entity types (side-varying)
19:                   okved # Party industry code from the business register (side-varying)
20:           okved_section # Party industry section code (side-varying)
21:  okved_section_name_eng # Party industry section name (in English) (side-varying)
22:      okved_chapter_name # Party industry chapter name (in Russian) (side-varying)
23:                   okopf # Party legal form from the business register (side-varying)
24:                     age # Party age since establishment (from the business register) (side-varying)
25:            total_assets # Party total assets in 2012-2018 (2020 rubles) (from the Rosstat open data) (side-varying)
26:              net_assets # Party net assets in 2012-2018 (2020 rubles) (from the Rosstat open data) (side-varying)
27:               staffsize # Party staff size in 2017-2019 (persons) (from the Federal Tax Service data) (side-varying)
28:              instanceId # ID of case instance (instance-varying)
29:          instanceNumber # Case number in a given instance (instance-varying)
30:                    date # Date case appeared in a given instance (instance-varying)
31:               courtName # Court name (instance-varying)
32:                courtTag # Court tag (instance-varying)
33:         presiding_judge # Name of the presiding judge in the case (instance-varying)
34:       presiding_judgeId # ID of the presiding judge (instance-varying)
35:               judgeId_1 # Name of the first judge in the case (instance-varying)
36:                 judge_1 # ID of the first judge in the case (instance-varying)
37:               judgeId_2 # <...>
38:                 judge_2 # <...>
39:               judgeId_3 # <...>
40:                 judge_3 # <...>
41:               judgeId_4 # <...>
42:                 judge_4 # <...>
43:               judgeId_5 # <...>
44:                 judge_5 # <...>
45:             publishDate # Date the decision was published (instance-varying)
46:                claimSum # Claim sum (current rubles) (instance-varying)
47:             recoverySum # Recovered sum (current rubles) (instance-varying)
48:              resultCode # Result code (instance-varying)
49: countDocumentsByParties # Count of documents issued by parties (instance-varying)
50:   countDocumentsByCourt # Count of documents issued by court (instance-varying)
51:       claimSum_deflated # Claim sum (2020 rubles) (instance-varying)
52:    recoverySum_deflated # Recovered sum (2020 rubles) (instance-varying)
53:         parties_present # Was any representative of a given party present in a given hearing (side-instance-varying)
54:          representative # Surname and name of a party representative (side-instance-varying)
```

## Data availability statement

The data that support the findings of this study were derived from the following resources:
- [Casebook](http://casebook.ru) data on the universe of cases in Crimea and Krasnodar purchased by the Institute for the Rule of Law at the European University at St. Petersburg
- [EGRUL](https://egrul.nalog.ru) data on the universe of legal entities from the Federal Tax Service purchased by the Institute for the Rule of Law at the European University at St. Petersburg 
- [EGRIP](https://www.nalog.gov.ru/rn77/related_activities/registries/egrul_egrip/) data on the universe of individual entrepreneurs from the Federal Tax Service purchased by the Institute for the Rule of Law at the European University at St. Petersburg
- [Financial statements data](https://rosstat.gov.ru/opendata?tag=&updated_from=&updated_to=&search=бухгалтерская&search_by_name=on&sort=&per_page=10) for 2012-2018 published by the Russian Statistical Service (Rosstat) under permissible licence
- [Enterprise register](https://rosstat.gov.ru/opendata/7708234640-urid1) for 2014-2019 published by the Russian Statistical Service (Rosstat) under a permissible licence

## Licence
<a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />
Creative Commons License Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0).

Moral rights belong to the respective contributors, as shown by the `AUTHORS` file.

## Contacts
Dmitriy Skougarevskiy, Ph.D.
[dskougarevskiy@eu.spb.ru](mailto:dskougarevskiy@eu.spb.ru)
